// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const Ymd = new Date()
exports.main = async(event, context) => {
  try {
    await db.collection('Option').where({
      userId: event.stuId,
      topicId: event.topicId
    }).remove()
    await db.collection('Message').add({
      data: {
        sendId: event.stuId,
        sendName: event.stuName,
        receiveId: event.teaId,
        messageType: '撤回选题申请',
        topicId: event.topicId,
        topicName: event.topicName,
        time: Date.parse(new Date()),
        dateYmd: Ymd.getFullYear() + '/' + (Ymd.getMonth() + 1) + '/' + Ymd.getDate()
      }
    })
    return {
      result: 1
    }
  } catch (e) {
    return {
      result: 0
    }
  }

}